package com.zg.common.core.converter;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import javax.annotation.Nonnull;
import java.sql.Timestamp;

/**
 * 将字符串转java.sql.Timestamp
 * @author Zxb
 */
@Component
public class TimestampConverter implements Converter<String, Timestamp> {

    @Override
    public Timestamp convert(@Nonnull String source) {
        if(StrUtil.isBlank(source)){
            return null;
        }
        return new Timestamp(DateUtil.parse(source,"yyyy-MM-dd HH:mm:ss").getTime());
    }

}
